package no.hib.dat102;
import no.hib.dat102.adt.MediaArchiveADT;


public class MediaArchive2 implements MediaArchiveADT{
    private int count;  
    private LinearNode<CD> top; 

    /**
     * Creates an empty stack.
     */
    public MediaArchive2(){
        count = 0;
        top = null;
    }
    
    /**
	 * Get a trimmed table of media objects from MediaArchive
	 * @return Table of media objects
	 */
    
    public Object[] GetTable() {
		//Fylles ut
		return null;
	}
    
    /**
     * Adds the specified media to the top of this stack.
     * @param media media to be pushed on stack
     */
    public void Add(T media){
        LinearNode<T> temp = new LinearNode<T>(media);

        temp.setNext(top);
        top = temp;
        count++;
    }

    /**
     * Removes the media at the top of this stack and returns a
     * reference to it. 
     * @return media from top of stack
     * @throws EmptyCollectionException if the stack is empty
     */
    
    
    public T Delete() throws EmptyCollectionException{
        if (isEmpty())
            throw new EmptyCollectionException("stack");

        T result = top.getmedia();
        top = top.getNext();
        count--;
 
        return result;
    }
   
    
    /**
	 * Search and return trimmed table of media objects from partial title string (match any part of title)
	 * @param partialstring to compare titles with
	 * @return table of media objects
	 */
    public Object[] SearchTitle(String partialString) {
    	
    	//Fylles ut
    }
    
    
    /**
	 * Search and return trimmed table of media objects from partial artist string (match any part of artist)
	 * @param partialstring to compare artists with
	 * @return table of media objects
	 */
    public Object[] SearchArtist(String partialString) {
    	//Fylles ut
    }
    
    
    /**
	 * Get the amount of media objects in the MediaArchive
	 * @return number(int) of media objects
	 */
    public int GetAmountGenre(Genre genre) {
    	
	 //Fylles ut
    }
    
    

    /**
     * Returns true if this stack is empty else false. 
     * @return true if stack is empty
     */
    public boolean isEmpty()
    {
    	return (count==0);
    }
 
    /**
     * Returns the number of medias in this stack.
     * @return number of medias in the stack
     */
    public int GetAmount()
    {
    	return count;
    }

    /**
     * Returns a string representation of this stack. 
     * @return string representation of the stack
     */
    public String toString()
    {
    	  String result = "";
          LinearNode current = top;

          while (current != null)
          {
             result = result + (current.getmedia()).toString() + "\n";
             current = current.getNext();
          }

          return result;
       }

	






    	
    }